<!doctype html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <link href="css/mui.css" rel="stylesheet"/>
    <link rel="stylesheet" type="text/css" href="css/header.css"/>
</head>

<body>
<header class="mui-bar mui-bar-nav title">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"
       style="color: #C8C7CC;"></a>
    <!-- <a id="finish" class=" mui-pull-right"
       style="color: #C8C7CC;font-size: 16px;line-height: 25px;">
				<img src="image/download.png" width="23px" style="line-height: 40px;"/>
			 </a> -->
    <a id="finish" class="mui-pull-right" style="font-size: 15px;color: white;line-height: 44px;">
        <img src="image/download.png" width="20px"/>
    </a>
    <h1 class="mui-title title-color">我的二维码</h1>
</header>

<header class="mui-bar mui-bar-nav title" style="position: fixed;">
    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left title-color"></a>
    <a id="linx_download_qrcode" class="mui-pull-right" style="font-size: 15px;color: white;line-height: 44px;">
        <img src="image/download.png" width="20px"/>
    </a>
    <h1 class="mui-title title-color"><b id="chatting-nickname">我的二维码</b></h1>
</header>

<div id="mui-content" style="padding: 80px 30px 0px 30px;">
    <div style="background-color: white;padding-top: 20px;padding-left: 20px;">
        <img id="img_myface" src="" width="60px" style="border-radius: 8%;float: left; margin-left: 10px"
             src="image/face.jpeg"/>
        <label id="lab_nickname" style="float: left;margin-left: 10px;margin-top: 22px; font-size: 20px ;">昵称</label>
    </div>
    <div style="background-color: white;text-align: center;">
        <img id="img_my_qrcode" src="image/face.jpeg"/>
    </div>
    <div style="background-color: white;text-align: center;">
        <p style="padding-bottom: 10px;font-size: 12px;">扫一扫上面的二维码图案，加我微信</p>
    </div>
</div>

<script src="js/app.js"></script>
<script src="js/mui.js"></script>
<script type="text/javascript">
    mui.init();
    mui.plusReady(function () {
        //获取缓存
        var user = app.getUserGlobalInfo();

        if (user != null) {

            //获取
            var lab_nickname = document.getElementById("lab_nickname");
            var img_my_qrcode = document.getElementById("img_my_qrcode");
            var img_myface = document.getElementById("img_myface");

            //更新数据
            //昵称
            lab_nickname.innerText = user.nickname;
            //显示二维码
            img_my_qrcode.src = app.imgServerUrl + user.qrcode;
            if (app.isNotNull(user.faceImage)) {
                //显示头像
                img_myface.src = app.imgServerUrl + user.faceImage;
            } else {
                //提示信息
                app.showToast("未上传头像", "error");
            }

        } else {
            //提示信息
            app.showToast("用户信息过期请重新登录", "error");
            //如果登录信息失效则返回登录页面
            app.returnLogin();
            return false;
        }

        //点击下载二维码
        var linx_download_qrcode = document.getElementById("linx_download_qrcode");
        linx_download_qrcode.addEventListener("tap", function () {

            //显示等待框
            plus.nativeUI.showWaiting("下载中...");
            //下载图片
            var user = app.getUserGlobalInfo();
            if (user != null) {
                var dtast = plus.downloader.createDownload(
                    app.imgServerUrl + user.qrcode,
                    {},
                    function (downloadFile, status) {
                        if (status == 200) {
                            //临时文件
                            var tempFile = downloadFile.filename;
                            //保存照片到相册
                            plus.gallery.save(tempFile, function () {
                                    //关闭等待框
                                    plus.nativeUI.closeWaiting();
                                    app.showToast("保存照片成功", "success");
                                }
                            );
                        } else {
                            //关闭等待框
                            plus.nativeUI.closeWaiting();
                            app.showToast("下载失败,请稍后重试", "error");
                            console.log("下载失败");
                        }
                    }
                );
                dtast.start();
            } else {
                //如果登录信息失效则返回登录页面
                app.returnLogin();
                //关闭等待框
                plus.nativeUI.closeWaiting();
            }
        });

    });

</script>
</body>

</html>
